package cn.wolfcode.redis.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

@RestController
@RequestMapping("/articles")
public class ArticleController {

    @Autowired
//    private StringRedisTemplate template;
    private JedisPool jedisPool;

    @PostMapping("/read")
    public Integer read(){
        Jedis jedis = jedisPool.getResource();
        jedis.setnx("read", "0");
        Long read = jedis.incr("read");
//        template.opsForValue().setIfPresent("read", "0");
//        Long read = template.opsForValue().increment("read", 1);
        return read.intValue();
    }
}
